package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.domain.vo.AddressVO;
import com.dongdongshop.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    //增加地址信息
    @PostMapping
    public Result addAddress(@RequestBody AddressVO addressVO, @RequestHeader String AutharizeToken){
        addressService.addAddress(addressVO,AutharizeToken);
        return Result.OK();
    }

    //查询该用户的全部地址
    @GetMapping
    public Result selectArea(@RequestHeader String AutharizeToken){
        List<AddressVO> addressVOList = addressService.selectArea(AutharizeToken);
        return Result.OK().setData(addressVOList);
    }

    //根据id查询地址信息
    @PostMapping("selectById")
    public Result selectById(@RequestParam Long id){
        AddressVO addressVO = addressService.selectById(id);
        return Result.OK().setData(addressVO);
    }

}
